package main

import (
	"fmt"
	"math"
)

func main() {
	res := cal(add, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
	fmt.Println("res=", res)

	params(1, 2, 3, 4, 5)
	a, b := 100, 200
	var ret int

	ret = max(a, b)
	fmt.Println("ret=", ret)

	fmt.Println("=====================")

	c, d := swap("hello", "world")
	fmt.Println(c, d)

	fmt.Println("=====================")

	// getSqrt := func(x float64)float64  {
	// 	return math.Sqrt(x)
	// }

	fmt.Println("getSqrt", getSqrt(9))

	fmt.Println("no-name", func() int { return 123 }())

	sum, sub := test(1, 2)
	fmt.Println(sum, sub)

}

type calFunc func(args ...int) int

func cal(cal calFunc, args ...int) int {
	return cal(args...)
}

func add(args ...int) int {
	sum := 0
	for _, val := range args {
		sum += val
	}
	return sum
}

// 不定参数
func params(arg ...int) {
	fmt.Println("arg", arg)
}

func test(x, y int) (sum int, sub int) {
	sum = x + y
	sub = x - y
	return
}

func getSqrt(x float64) float64 {
	return math.Sqrt(x)
}

// 返回最大值
func max(num1, num2 int) int {
	var result int

	if num1 > num2 {
		result = num1
	} else {
		result = num2
	}

	return result
}

// 交换两个字符串输出
func swap(x, y string) (string, string) {
	return y, x
}
